﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace KerriganBlog
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        private string requestCookie;
        private bool isAnonymous;

        protected void Page_Load(object sender, EventArgs e)
        {
            using (ServiceProxy Srv = new ServiceProxy(Request.Cookies))
            {

                try
                {

                    requestCookie = Request.Cookies["AXPXAUTHFWC"].Value;

                }
                catch (Exception ex)
                {
                    requestCookie = null;
                }

                if (requestCookie == null )
                {
                    LinkButtonManageBlog.Visible = false;
                }
                else if (requestCookie != null )
                {
                    if (CheckUser(requestCookie) == true)
                    {

                        LinkButtonManageBlog.Visible = true;
                    }
                    else {

                        LinkButtonManageBlog.Visible = false;
                    
                    }
                }

            }
        }

        public static Boolean CheckUser(String requestCookie)
        {
            Boolean result = false;
            using (ServiceProxy Srv = new ServiceProxy())
            {


                if (requestCookie != null)
                {
                    FormsAuthenticationTicket authentification = FormsAuthentication.Decrypt(requestCookie);
                    string user = authentification.UserData;
                    string[] infosUser = user.Split(',');
                    result = true;

                }
                else
                {

                    result = true;

                }


            }

            return result;
        }
    }
}